<!--
 * @Author: yao
 * @Date: 2024-11-21 08:31:44
<<<<<<< HEAD
 * @LastEditTime: 2025-02-18 17:37:32
=======
 * @LastEditTime: 2025-02-05 23:39:48
>>>>>>> 1b6dd3c15f0f0fca2b3ab51833658be417980567
 * @LastEditors: yao
 * @Description: 
 * @FilePath: \jdev-web-el\src\Layouts\BaseLayout.vue
-->
<template>
  <el-container id="baseLayout" ref="baseLayout" class="base_layout">
    <el-header height="55px" class="base_header">
      <JHeader />
    </el-header>
    <div class="base_main">
      <router-view v-slot="{ Component }">
        <transition @before-enter="beforeEnter" @enter="enter" @leave="leave" :css="false">
          <component class="main" :is="Component" ref="pageComponent" />
        </transition>
      </router-view>
    </div>
    <Dock id="dock"></Dock>
  </el-container>
</template>

<script setup lang='ts'>
import { useRoute } from 'vue-router';
import { onMounted, onUnmounted, ref } from 'vue';
import { gsap } from 'gsap';
import JHeader from './JHeader.vue';
import { throttle } from 'lodash';
const route = useRoute();
const pageComponent = ref<HTMLElement | null>(null);
const baseLayout = ref<HTMLElement>()

// 计算 Dock 的位置（屏幕底部中央）
const calculateDockPosition = () => {
  const windowWidth = window.innerWidth;
  const windowHeight = window.innerHeight;
  return {
    x: windowWidth / 2 - 50, // 假设 Dock 图标宽度为 100px
    y: windowHeight - 100, // 假设 Dock 距离底部 100px
  };
};

const beforeEnter = (el: HTMLElement) => {
  // 初始状态：隐藏并缩小
  gsap.set(el, {
    scale: 0,
    opacity: 0,
    y: document.getElementById('dock')?.offsetTop - 230,
    x: 0
  });
};

const enter = (el: HTMLElement, done: () => void) => {
  // 进入动画：从 Dock 弹出
  const dockPosition = calculateDockPosition();

  gsap.to(el, {
    duration: 0.9,
    scale: 1,
    opacity: 1,
    x: 0,
    y: 0,
    ease: 'back.inOut(0.8)',
<<<<<<< HEAD
    onStart: function () {
      // 在动画开始之前隐藏滚动条
      const parent = document.querySelector('.base_layout');
      if (parent && parent.style) {
        parent.style.overflowX = 'hidden';
        parent.style.overflowY = 'scroll';
      }
    },
    onComplete: function () {
      // 动画完成后恢复滚动条
      const parent = document.querySelector('.base_layout');
      if (parent && parent.style) {
        parent.style.overflowX = 'auto';
        parent.style.overflowY = 'scroll';
      }
    }
=======
    onStart: done
>>>>>>> 1b6dd3c15f0f0fca2b3ab51833658be417980567
  });

};

const leave = (el: HTMLElement, done: () => void) => {
  // 离开动画：缩小并移动到 Dock
  const dockPosition = calculateDockPosition();
  gsap.to(el, {
    duration: 0.4,
    scale: 0,
    opacity: 0,
    x: 20,
    y: document.getElementById('dock')?.offsetTop - 230,
    ease: 'back.inOut(0.7)',
    onComplete: done,
  });
};

</script>
<style scoped lang='scss'>
.base_layout {
  height: 100vh;
  width: 100%;
  overflow-y: scroll;
  overflow-x: auto;
  box-sizing: border-box;
  display: block;

  .base_main {
    margin: 24px 0 0 22px;
    width: calc(100% - 36px);

    .main {
      padding: 20px;
      min-height: calc(100vh - 11rem);
      width: 100%;
      border-radius: 12px;
      overflow: hidden;
      box-sizing: border-box;
      background: var(--ep-base-background);
      backdrop-filter: blur(20px);
      box-shadow:
        inset 0 0 0 1px rgba(255, 255, 255, 0.6),
        0 12px 24px -6px rgba(0, 0, 0, 0.08);
      box-sizing: border-box;
    }
  }

  .base_header {
    position: sticky;
    top: 0;
    left: 0;
    width: 100%;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    z-index: 1000;
  }
}

/* 滚动条样式保持不变 */
.base_layout::-webkit-scrollbar {
  width: 8px;
  height: 8px;
  /* 水平滚动条宽度 */
}

.base_layout::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, 0.39);
  border-radius: 10px;
  transition: all .2s ease-in-out;
}

.base_layout::-webkit-scrollbar-thumb:hover {
  background-color: #0000004d
}

.base_layout::-webkit-scrollbar-track {
  background-color: transparent;
}

/* 添加一个伪元素以覆盖滚动条顶部55px的高度 */
.base_layout::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 8px;
  height: 55px;
  background: rgba(0, 0, 0, 0.3);
  pointer-events: none;
  z-index: 10;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
</style>
